﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;


/// <summary>
/// Summary description for DBUtils
/// </summary>
public static class Util
{
    private static MySqlConnection _con;

    public static MySqlConnection con()
    {
        MySqlConnection conn = new MySqlConnection(getConStr());
        return conn;
    }

    public static MySqlConnection con(bool newInstance)
    {
        if(newInstance)
            _con = new MySqlConnection(getConStr());
        return _con;
    }

    public static string getConStr()
    {
        return ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
    }

    public static string getNextPaddingNumber(char pad, string prefix, string suffix, int lastNumber, int length)
    {
        string val = prefix + lastNumber.ToString().PadLeft(length, pad) + suffix;
        return val;
    }

    public static T isNull<T>(object value, T returnValue)
    {
        if (value == DBNull.Value || value == null)
        {
            return returnValue;
        }
        else
            return (T)value;
    }
}

